package com.lw.state;

/**
 * @author LW
 * @2020/8/17 22:51
 */
public class TestDaemon {

    public static void main(String[] args) {
        God god = new God();
        You you = new You();
        Thread thread = new Thread(god);
        thread.setDaemon(true);//默认是false表示用户线程，正常的线程是用户线程。
        thread.start();//上帝守护线程开启
        new Thread(you).start();//用户线程启动
        //用户线程结束后，虚拟机停止需要一点时间。守护线程才会停止
    }
}

class God implements Runnable{

    @Override
    public void run() {
        while (true){
            System.out.println("God daemon");
        }
    }
}

class You implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("人生不过三万天");
        }
        System.out.println("see you again");
    }
}